package com.twu.biblioteca;

/**
 * Created by thoughtworks on 27/7/14.
 */
public class Book  extends Item{
    private int bookId;
    private String name;
    private String author;
    private String publisher;
    private String yearOfPublication;
    private static int bookCount = 1001;
    private boolean available;

    public Book(String name, String author, String publisher, String yearOfPublication) {
        bookId = bookCount++;
        this.name = name;
        this.author = author;
        this.publisher = publisher;
        this.yearOfPublication = yearOfPublication;
        available = true;
    }

    public String getName() {
        return name;
    }

    public String[] getBookDetails() {
        String[] details = new String[4];
        details[0] = name;
        details[1] = author;
        details[2] = publisher;
        details[3] = yearOfPublication;
        return details;
    }

    public boolean isAvailable() {
        return available;
    }

    public boolean checkOut() {
        if(this.isAvailable())
        {
            this.available = false;
            return true;
        }
        return false;
    }

    public boolean checkIn() {
        if(!this.isAvailable())
        {
            this.available = true;
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return bookId + "\t" + name + "\t" + author + "\t" + publisher + "\t" + yearOfPublication;
    }

    @Override
    public boolean equals(Object obj) {
        Book book = (Book) obj;
        if(this.name  == book.name && this.author  == book.author && this.publisher  == book.publisher && this.yearOfPublication  == book.yearOfPublication)
            return true;
        return false;
    }

    public int getBookId() {
        return bookId;
    }
}
